<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('业务员列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <form id="formId">
            <div class="select-list">
                <ul>
                    <input id="customerId" name="customerId" th:value="${customer.id}" type="hidden">
                    <li>
                        <p>标识：</p>
                        <select name="identification" th:with="type=${@dict.getType('custome_identification')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
                    </li>
                </ul>
            </div>
        </form>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary" onclick="selectMemberTree()" shiro:hasPermission="system:share:add">
                <i class="fa fa-edit"></i> 添加共享
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:share:remove">
                <i class="fa fa-remove"></i> 删除共享
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('system:share:remove')}]];
    var identificationDatas = [[${@dict.getType('custome_identification')}]];
    var prefix = ctx + "system/share";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            removeUrl: prefix + "/remove",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "业务员",
            columns: [{
                checkbox: true
            },
                {
                    field : 'id',
                    title : 'id',
                    visible: false
                },
                {
                    field : 'nickName',
                    title : '昵称',
                    align: 'left'
                },
                {
                    field : 'realName',
                    title : '真实姓名',
                    align: 'left'
                },
                {
                    field : 'memberTelephone',
                    title : '手机号',
                    align: 'left'
                },
                {
                    field : 'identification',
                    title : '标识',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(identificationDatas, value);
                    }
                },
                {
                    field : 'createTime',
                    title : '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除共享</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function submitHandler() {
        $.modal.close();
    }

    /*业务员-新增-选择父部门树*/
    function selectMemberTree() {
        var options = {
            title: '业务员选择',
            width: "800",
            url: prefix + "/selectMemberTree/" + $("#customerId").val(),
            callBack: doSubmitMember
        };
        $.modal.openOptions(options);
    }

    function doSubmitMember(index, layero){
        var body = layer.getChildFrame('body', index);
        if(body.find('#treeId').val()==''){
            $.modal.alertWarning('请选择业务员！')
            return;
        }
        layer.close(index);
        $.operate.submit(
            prefix + "/add",
            "post",
            "json",
            {"customerId": $("#customerId").val(),
            "memberId": body.find('#treeId').val()}
        );
    }

</script>
</body>
</html>